GtkBuilder: Emit a more detailed error for templates
authorMatthias Clasen <mclasen@redhat.com>
Thu, 30 Apr 2015 05:21:26 +0000 (01:21 -0400)
committerMatthias Clasen <mclasen@redhat.com>
Thu, 30 Apr 2015 10:19:10 +0000 (06:19 -0400)
Add the class and parent class name to the error message.
gtk-builder-tool will parse the error message and use the
class names for trying again to parse the file as a template.

gtk/gtkbuilderparser.c

index 998357de483c0ebf36fa2323d36352f061964540..160c7bcdb5e48b4f2cf8f1129d8fea6b45877947 100644 (file)
@@ -420,23 +420,28 @@ parse_template (GMarkupParseContext  *context,
 
   template_type = _gtk_builder_get_template_type (data->builder);
 
-  if (template_type == 0)
+  if (!g_markup_collect_attributes (element_name, names, values, error,
+                                    G_MARKUP_COLLECT_STRING, "class", &object_class,
+                                    G_MARKUP_COLLECT_STRING|G_MARKUP_COLLECT_OPTIONAL, "parent", &parent_class,
+                                    G_MARKUP_COLLECT_INVALID))
     {
-      error_unhandled_tag (data, "template", error);
+      _gtk_builder_prefix_error (data->builder, data->ctx, error);
       return;
     }
-  else if (state_peek (data) != NULL)
+
+  if (template_type == 0)
     {
-      error_invalid_tag (data, "template", NULL, error);
+      g_set_error (error,
+                   GTK_BUILDER_ERROR,
+                   GTK_BUILDER_ERROR_UNHANDLED_TAG,
+                   "Not expecting to handle a template (class '%s', parent '%s')",
+                   object_class, parent_class ? parent_class : "GtkWidget");
+      _gtk_builder_prefix_error (data->builder, context, error);
       return;
     }
-
-  if (!g_markup_collect_attributes (element_name, names, values, error,
-                                    G_MARKUP_COLLECT_STRING, "class", &object_class,
-                                    G_MARKUP_COLLECT_STRING|G_MARKUP_COLLECT_OPTIONAL, "parent", &parent_class,
-                                    G_MARKUP_COLLECT_INVALID))
+  else if (state_peek (data) != NULL)
     {
-      _gtk_builder_prefix_error (data->builder, data->ctx, error);
+      error_invalid_tag (data, "template", NULL, error);
       return;
     }